<?php

/*

  Action	$4

  +1 Action
  Reveal the top 4 cards of your deck.
  Put the revealed Victory cards into your hand.
  Put the other cards on top of your deck in any order.

 */

class Scout extends Card implements iAction, iKingdom, iIntrigue {

    public function __construct() {
        parent::__construct("Scout", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Action",
            "Reveal the top 4 cards of your deck.  Put the revealed Victory cards into your hand.  Put the other cards on top of your deck in any order.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action", "gets +1 action");

        $reordercards = array();
        $drawed_cards = array();
        for ($i = 0; $i < 4; $i++) {
            $card = $game->peekCardFromDrawDeck();
            if (!$card)
                break;
            if ($card instanceof iVictory) {
                $d_cards = $game->drawCards(1);
                $drawed_cards[] = $d_cards[0];
            } else {
                $card = $game->removeCardFromDrawDeck();
                $reordercards[] = $card;
            }
        }

        ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($reordercards) . " and put " . nicePrint($drawed_cards) . " in hand", "reveals " . nicePrint($reordercards) . " and puts " . sizeof($drawed_cards) . " cards in hand");
        if (sizeof($reordercards) > 0) {
            $unique_reordercards = getUniqueCards($reordercards);
            if (sizeof($unique_reordercards) > 1) {
                $output = MySocket::GetUserReply($game, Input_Reorder, $reordercards, -1, -1, null, "Put cards back in any order");
            } else {
                $output = $reordercards;
            }
            ScreenDisplay::addScreenMessage($game, true, "put " . nicePrint($output) . " back on top of your deck", "puts " . sizeof($output) . " cards on top of his deck");
            $output = array_reverse($output);
            foreach ($output as $p) {
                $game->putCardOnTopOfDrawDeck($p);
            }
        }
        $game->cardActionFinished();
        return true;
    }

}

?>